package 常用集合与排序;

import javafx.util.Pair;

import java.util.*;

/**
 * 妙啊，用做二维数组压缩，Pair就是一对二维下标
 */
public class MapPair {
    public static void main(String[] args) {

        Pair<String, String> p = new Pair<>("a", "b");
        Pair<String, String> q = new Pair<>("a", "b");

        System.out.println("p和q的等价关系:" + p.equals(q));//true


        System.out.println("p的hashCode:" + p.hashCode() + "|q的hashCode:" + q.hashCode());//一样的值
        Map<Pair<String, String>, Integer> map = new HashMap();
        System.out.println("map存入p");
        map.put(p, 1);

        System.out.println("用q做key做查询:" + map.containsKey(q));
        map.put(q, 2);

        // 会覆盖。
        for (Pair<String, String> key : map.keySet()) {
            System.out.println("key:" + key + "|value:" + map.get(key));
        }
    }
}
